package xyz.nizhipeng.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.nizhipeng.domain.UserInfo;
import xyz.nizhipeng.service.UserinfoService;

import java.util.List;

@RestController
@RequestMapping("/userinfo")
public class UserinfoController {

    @Autowired
    private UserinfoService userinfoService;

    @GetMapping("/findAll")
    public List<UserInfo> findAll(){
        return userinfoService.findAll();
    }

    @PostMapping("/login")
    public String login(@RequestBody UserInfo userInfo){
        List<UserInfo> list = userinfoService.login(userInfo.getName());
        if (list.size() > 0) {
            if (list.get(0).getPassword().equals(userInfo.getPassword())){
                return "登录成功";
            }else{
                return "密码错误";
            }
        }else{
            return "用户不存在";
        }
    }

}
